home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c,comp.lang.c.moderated,hp.unix,comp.sys.hp.apps,comp.sys.hp.hpux
- Subject: Re: C coding problem
- Date: 25 Mar 1996 06:26:52 -0600
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4j63ec$3l7@solutions.solon.com>
- References: <4ianbf$h86@solutions.solon.com> <4iemcl$a05@solutions.solon.com> <4io1io$no4@solutions.solon.com> <4j06na$808@solutions.solon.com>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <4j06na$808@solutions.solon.com>,
- Gary Quakenbush <garyq@hpfcla.fc.hp.com> wrote:
- >Konrad Schwarz (schwarz@mips.complang.tuwien.ac.at) wrote:
- >: One of C's most defining attributes is the pointer concept
- >: which includes the mapping of arrays to pointer arithmetic. If you're
- >: going to fight it, it might be better to switch to some other programming
- >: language.
- >
- >: I recently wrote a loop that went like this:
- >
- >: while (p < end_p)
- >: ++*p++;
- >
- >: Maybe some will find it a counter-example; I think it's good
- >: code that embodies the way C is designed to work. Arrays are
- >: second rate objects in C. Use pointers.
- >
- >Ok, I'll bite.
- >
- >This could be useful as an interview question.
- >
- >Interviewee gets points for quickly locating in C reference the info
- >needed to understand this.
-
- Interviewee should know this if he or she purports to be a C programmer,
- without needing a reference.
-
- The precedence and associativity of the language is such that the p++ is parsed
- first. The value of p is noted, and p is then incremented. This noted value is
- then dereferenced, and the object previously pointed at by p is incremented.
- The * and ++ operators have the same precedence.
-
- >Interviewee gets extra points for mentioning maintainability tradeoffs.
-
- I wouldn't mention any such thing. It's a perfectly unambigous and maintainable
- statement.
-
- >Interviewee gets hired if she rewrites to be trivial for "contractor of
- >the month" to understand and maintain.
-
- I'd suggest extra parentheses:
-
- ++*(p++);
- --
-